<template>
	<view class="box">
		<view class="box-header">
			¥{{price}}
		</view>
		<view class="box-radio">
			<view class="box-radio-left">
				<u-icon name="https://duomi.bigchun.com/imgs/vip/wePay.png" size="30" color="#09BB07" style="margin-right: 24rpx;"></u-icon>
				<view class="">
					微信支付
				</view>
			</view>
			<view class="box-radio-right">
				<u-radio-group v-model="value">
					<u-radio name="1" activeColor="#FC5351"></u-radio>
				</u-radio-group>
			</view>
		</view>
		<view class="box-footer" @click="createPLay">
			确认支付
		</view>
    <view class="tishi" v-if="typeId!=1&&!is_pay">
      <view class="tishititle">
        温馨提示：
      </view>
      <view class="tishiitem">
        先付全款、后返差价！
      </view>
    </view>
    <view class="tishi" v-if="typeId!=1&& is_pay">
      <view class="tishititle">
        温馨提示：
      </view>
      <view class="tishiitem">
        已支付全款。
      </view>
      <view class="tishiitem">
        邀约更多人参与拼团，提高拼团速度。
      </view>
      <view class="tishiitem">
        坐等差价返回 ~
      </view>
    </view>
		<u-modal v-model="fxShow" :show-cancel-button="true" @cancel="routeBack" content="快去邀请微信好友, 一起成为多米会员吧">
			<view slot="confirm-button">
				<button open-type="share"
					style="height: 110rpx;display: flex;justify-content: center;align-items: center;background: none;font-size: 32rpx;">发给微信好友</button>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				value: 1,
				vip_id: '',
				typeId: '',
				price: 0,
				fxShow: false,
				pink_id: 0,
				shareOrderId: '',
        lock:true,
        is_pay:false
			}
		},
		onLoad(option) {
			this.vip_id = option.id
			this.typeId = option.typeId
			this.price = option.price
			if (option.pink_id) this.pink_id = option.pink_id
      this.paduanispay()
		},
		computed: {
			...mapGetters(['userInfo'])
		},
		methods: {
		  paduanispay(){
        this.$https('common.isPay', {
          token: uni.getStorageSync("token"),
        }).then(res => {
          console.log('返回的参数', res)
          if(res.code=='1'){
            this.is_pay = res.data.is_pay
          }
        })
      },
			// 返回页面
			routeBack() {
				uni.navigateBack()
			},
			// 创建支付订单
			createPLay() {
			  if(this.lock){
          this.lock = false
          const data = {
            type: this.typeId,
            id: this.vip_id,
            pink_id: this.pink_id
          }
          console.log("创建订单", data)
          this.$https('vip.createVipOrder', data).then(res => {
            console.log('返回的参数', res)
            let typeId = this.typeId
            let self = this;
            this.shareOrderId = res.data.vip_pink_id
            if (res.code == 2) {
              uni.showToast({
                title: res.msg,
                icon: 'none'
              })
              self.fxShow = true
              return
            }
            wx.requestPayment({
              timeStamp: res.data.pay_data.timeStamp,
              nonceStr: res.data.pay_data.nonceStr,
              package: res.data.pay_data.package,
              signType: res.data.pay_data.signType,
              paySign: res.data.pay_data.paySign,
              success(res) {
                self.$u.toast('支付成功');
                self.lock = true;
                setTimeout(() => {
                  if (typeId == 2) {
                    self.fxShow = true
                    setTimeout(() => {
                      uni.navigateBack()
                    }, 5000)
                  } else {
                    uni.navigateBack()
                  }
                })
              },
              fail(err) {
                self.$u.toast('支付失败');
              }
            })
          })
        }
			},

		},
		onShareAppMessage() {
			let screnObj = {}
			if (this.shareOrderId) screnObj = { vip_pink_id: this.shareOrderId, shareVipType: 1, userId: uni.getStorageSync('userInfo').id}
      console.log(this.shareOrderId,"=========screnObj",screnObj)
			let path = `pages/user/wallet/tgListContent?${screnObj.vip_pink_id ? 'screnVipShareObj=' + JSON.stringify(screnObj) : ''}&id=${this.shareOrderId}&is_join=0&typeTitle=1`
			return {
				path,
				imageUrl: 'https://duomi.bigchun.com/imgs/vip/shareBg.jpg',
				title: '快来一起拼团吧~'
			}
		},
	}
</script>

<style scoped lang="less">
	.box {
		width: 100%;

		&-header {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 340rpx;
			font-size: 64rpx;
			font-weight: bold;
			color: #333333;
		}

		&-radio {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 20rpx;
			margin: 0 24rpx;
			background: #fff;
			height: 108rpx;

			&-left {
				display: flex;
			}
		}

		&-footer {
			height: 98rpx;
			margin: 0 24rpx;
			background: linear-gradient(90deg, #FC5351 0%, #FF6E6D 100%);
			border-radius: 74rpx;
			text-align: center;
			line-height: 98rpx;
			font-size: 32rpx;
			font-weight: bold;
			color: #FFFFFF;
			margin-top: 100rpx;
		}
	}
  .tishi{
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 20rpx;
    padding: 20rpx 40rpx;
    .tishititle{
      font-size: 26rpx;
      font-weight: bold;
      color:#333;
      display: flex;
      width: 100%;
    }
    .tishiitem{
      width: 100%;
      display: flex;
      align-items: center;
      padding:10rpx 0 0 0;
      font-size: 24rpx;
      color:#777777;
    }
  }
</style>
